<template>
  <div class="home-container">
    <!-- 首页导航 -->
    <van-nav-bar class="page-nav-bar" fixed>
      <van-button
        slot="title"
        round
        text="搜索"
        type="info"
        icon="search"
        class="search-btn"
        to="/search"
      ></van-button>
    </van-nav-bar>
    <!-- 标签页 -->
    <van-tabs class="channel-tabs" v-model="active" animated swipeable>
      <van-tab v-for="obj in articleList" :key="obj.id" :title="obj.name">
        <content-list :channel="obj"></content-list>
      </van-tab>
      <div slot="nav-right" class="placeholder"></div>
      <div slot="nav-right" class="hamburger-btn" is-link @click="showPopup">
        <i class="headLine headLine-gengduo"></i>
      </div>
    </van-tabs>
    <!-- 汉堡包 弹出 层 -->
    <van-popup
      v-model="show"
      closeable
      close-icon-position="top-left"
      position="bottom"
      :style="{ height: '100%' }"
    >
      <class-list
        @onChangeActive="setActive"
        :usrChannList="articleList"
        :active="active"
      ></class-list>
    </van-popup>
  </div>
</template>

<script>
//  导入 用户 频道 获取 api
import { userArticleListApi } from '@/api/index.js'
// 导入 自定义 封装的 localstorage 函数
import { getItem } from '@/utils/storage.js'
// 导入 用户 本地 配置 参数
import { userChannel } from '@/config/localName.js'
// 子组件 导入
import ContentList from './components/contentList.vue'
import classList from './components/classList.vue'
export default {
  name: 'home',
  data() {
    return {
      active: 0,
      articleList: [],
      // isShowOPtion: true,
      show: false
    }
  },
  created() {
    this.loadArticleList()
  },
  methods: {
    async loadArticleList() {
      try {
        const { data } = await userArticleListApi()
        //  当 没有用户 登录 或者 没有权限的 时候 进行 本地数据的 渲染
        this.articleList = this.$store.state.user
          ? data.data.channels
          : getItem(userChannel)
            ? getItem(userChannel)
            : data.data.channels
      } catch (err) {
        console.log(err)
      }
    },
    showPopup() {
      this.show = true
      console.log('1')
    },
    // 当数据 改变当前的 active数据
    setActive(i, isedit = true) {
      this.active = i
      // 关闭弹出层
      this.show = isedit
    }
  },
  components: {
    ContentList,
    classList
  }
}
</script>

<style lang='less' scoped>
.home-container {
  padding-top: 84px;
  /deep/.van-nav-bar__title {
    max-width: unset;
    .search-btn {
      background-color: #5babfb;
      width: 555px;
      height: 64px;
      border: none;
      font-size: 28px;
      .van-icon {
        font-size: 32px;
      }
    }
  }
  /deep/ .channel-tabs {
    margin-top: 100px;
    height: 79vh;
    overflow-y: auto;
    .van-tabs__wrap {
      position: fixed;
      width: 100%;
      top: 92px;
      z-index: 2;
    }
    .van-tab {
      min-width: 200px;
      border-right: 1px solid #edeff3;
    }
    .van-tabs__nav--line {
      padding-bottom: 0px;
    }
    .van-tab--active .van-tab__text {
      color: #333 !important;
    }
    .van-tabs__line {
      width: 31px !important;
      height: 6px;
      background-color: #5babfb;
      border-radius: 3px;
      bottom: 8px;
    }
    .placeholder {
      flex-shrink: 0;
      width: 50px;
      height: 82px;
    }

    .hamburger-btn {
      position: fixed;
      right: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 66px;
      height: 82px;
      background-color: #fff;
      opacity: 0.902;
      i.headLine {
        font-size: 33px;
      }
      &:before {
        content: '';
        position: absolute;
        left: 1px;
        width: 1px;
        height: 100%;
        background-image: url(~@/assets/gradient-gray-line.png);
        background-size: contain;
      }
    }
  }
}
</style>
